#!/bin/bash

set -e  # 一旦出错就退出

# 1.先清理构建目录
rm -rf build
rm -f *.log

# 2.创建构建目录
mkdir -p build/lib

# 3.创建IPC通道
mkdir -p Ipc
touch Ipc/log.ipc Ipc/logic.ipc Ipc/master.ipc Ipc/game.ipc Ipc/log2db.ipc Ipc/db2work.ipc

# 构建测试程序
cd src/test
g++ -g -O0 main.cpp luaManager.cpp crc32.cpp -o ../../engine/client -llua5.4
cd ../../

# 4.执行命令开始编译
cd build
cmake cmake -DCMAKE_BUILD_TYPE=Debug ../src
make -j2

# 5.编译网络模块的压力测试
cd ../src/net
g++ -g -O0 pressTest.cc ./utils/crc32.cc -I./include -o ../../engine/pressTest -std=c++17 -pthread


# 6. 编译Go数据库程序，开启调试信息
cd ../db/logdb
go build -gcflags "all=-N -l" -o ../../../engine/logdb
cd ../workdb
go build -gcflags "all=-N -l" -o ../../../engine/workdb
cd ../../../engine

echo "Built target db_gdb"